/-app
/-docs
/-files
/-fs ...
/-fs/attached
FileSystem.ts
/-imports
/-storage
/-typings
errors.js
functions.ts
index.html
try.js
​x
 
1
module teapo.fs {
2
  
3
  export interface FileSystem {
4
    
5
  }
6
​
7
  export function require(
8
    uniqueId: string,
9
    domDrive: fs.attached.SyncDrive,
10
    domTimestamp: number,
11
    dynamicDriveLoaders: fs.attached.DriveLoader[],
12
    callback: (error: Error, fs: FileSystem) => void) {
13
​
14
    var loadIndex = 0;
15
      
16
    tryLoadNext();
17
      
18
    function tryLoadNext() {
19
      
20
      if (loadIndex < dynamicDriveLoaders.length) {
21
        var loader = dynamicDriveLoaders[loadIndex];
22
      
23
        loader.load(uniqueId, (error, timestamp, files, drive) => { 
24
          if (error) {
25
            tryLoadNext();
26
          }
27
          else {
28
            dynamicDriveSearchCompleted(timestamp, files, drive);
29
          }
30
        });
31
      }
32
      else {
33
        dynamicDriveSearchCompleted(null, null, null);
34
      }
35
    }
36
     
37
    function dynamicDriveSearchCompleted(dynamicTimestamp: number, dynamicFiles: string[], drive: any) {
38
      if (drive) {
39
        var asyncDrive = <fs.attached.AsyncDrive>drive;
40
        if (asyncDrive.readAsync) { 
41
          if (dynamicTimestamp > domTimestamp) {
42
            // TODO: update DOM (asynchronously)
43
            return;
44
          }
45
          else {
46
            createFileSystemWithDynamicAsync();
47
            return;
48
          }
49
        }
50
        else {
51
          var syncDrive = <fs.attached.SyncDrive>drive;
52
          if (syncDrive.readSync) {
53
            if (dynamicTimestamp > domTimestamp) {
54
              // TODO: update DOM
55
            }
56
            createFileSystemWithDynamicSync();
57
            return;
34:5